<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Main extends CI_Controller {
        
    var $data = array();
    var $meta = array();
    var $limit_article;
    
    public function __construct() {
        parent::__construct();
        $this->load->helper('url');
        $this->load->model('articles');
        $this->load->model('categories');
        $this->config->load('go_blog');
        $this->meta['site_title'] = 'HaloDunia';
        $this->data['open'] = $this->load->view('template/open',$this->meta,TRUE);
        $this->data['close'] = $this->load->view('template/close','',TRUE);
        $this->data['topmenu'] = $this->load->view('main/topmenu','',TRUE);
        $this->meta['top_post'] = $this->articles->get_top_post();
        $this->meta['portfolio'] = $this->articles->get_article_by_category_name('portfolio');
        $this->limit_article = $this->config->item('article_each_page');
    }

    public function index() {
        $this->data['cright'] = $this->load->view('main/cright_front',$this->meta,TRUE);
        $article = $this->articles->get_all_published(TRUE,  $this->limit_article + 1);
        $info = array();
        $info['article'] = $article;
        $info['limit_article'] = $this->limit_article;
        $this->data['cleft'] = $this->load->view('main/cleft_front',$info,TRUE);
        $info = array();
        $info['curr_page'] = 1;
        $info['limit_article'] = $this->limit_article;
        $info['numrows'] = count($article);
        $this->data['post_nav'] = $this->load->view('main/cleft_nav',$info,TRUE);
        $this->load->view('main/front',$this->data);
    }
    
    public function view($article_id=null,$article_title=null) {
        if(empty($article_id) || empty($article_title)){
            show_404();
        }
        $article = $this->articles->get_article_by_id($article_id,TRUE);
        $this->articles->update_viewed_by_id($article_id,$article->viewed + 1);        
        $this->data['cright'] = $this->load->view('main/cright_front',$this->meta,TRUE);
        $image = $this->articles->get_image('article_id',$article_id);
        $this->data['cleft'] = $this->load->view('main/cleft_view',array('article' => $article,'image' => $image),TRUE);
        $this->load->view('main/front',$this->data);
    }
    
    public function page($curr_page = 1){
        $page = $curr_page - 1;
        $this->data['cright'] = $this->load->view('main/cright_front',$this->meta,TRUE);
        $article = $this->articles->get_all_published(TRUE,$this->limit_article + 1,$this->limit_article * $page);
        $info = array();
        $info['article'] = $article;
        $info['limit_article'] = $this->limit_article;
        $this->data['cleft'] = $this->load->view('main/cleft_front',$info,TRUE);
        $info = array();
        $info['curr_page'] = $curr_page;
        $info['limit_article'] = $this->limit_article;
        $info['numrows'] = count($article);
        $this->data['post_nav'] = $this->load->view('main/cleft_nav',$info,TRUE);
        $this->load->view('main/front',$this->data);
    }
    
    public function category($category = null){
        
    }
    
    public function portfolio(){
        $this->data['cright'] = '';
        $this->data['cleft'] = $this->load->view('template/under_construction','',TRUE);
        $this->load->view('main/front',$this->data);
    }
    
    public function true_indonesia(){
        $this->data['cright'] = '';
        $this->data['cleft'] = $this->load->view('template/under_construction','',TRUE);
        $this->load->view('main/front',$this->data);
    }
    
    public function about(){
        $this->data['cright'] = '';
        $this->data['cleft'] = $this->load->view('template/under_construction','',TRUE);
        $this->load->view('main/front',$this->data);
    }
}

?>